import os,json


def base_path():
    base_path=os.path.dirname(os.path.dirname(__file__))  # 读取运行的py文件所在的目录路径
    return base_path

def write_file(file_dir,content):
    with open(base_path() + file_dir, 'w') as  json_file:
        json_file.write(json.dumps(content,indent=4,ensure_ascii=False))
    # dir=base_path()+file_dir
    # print(dir)
    # return dir

def read_file(file_dir):
    f = open(base_path() + file_dir, 'r')
    read_file = json.loads(f.read())
    return read_file

# 格式化 字典、列表、json
def data_formatting(data):
    jsons = json.dumps(data, sort_keys=True, indent=12, separators=(',', ': '), ensure_ascii=False)
    return jsons

if __name__ == '__main__':
    base_path()